import { Component, Injector, ViewChild, Input } from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { Paginator } from 'primeng/components/paginator/paginator';
import { Table } from 'primeng/components/table/table';

import { WorkflowServiceProxy, UserServiceProxy, ExecutionPointerDto, OutsourcingWorkFlowServiceProxy, SupplierQuotationServiceProxy, SupplierQuotationModel } from '@shared/service-proxies/service-proxies';
import { finalize } from 'rxjs/operators';
import * as _ from 'lodash';
import * as moment from 'moment';
import { from } from 'rxjs';

@Component({
  selector: 'app-flowApprovalRecord',
  templateUrl: './FlowApprovalRecord.component.html',
  styleUrls: ['./FlowApprovalRecord.component.css']
})
export class FlowApprovalRecordComponent extends AppComponentBase {

  @Input() workflowid: any;
  constructor(injector: Injector,
    private _supplierquotationService: SupplierQuotationServiceProxy,
    private _workflowService: WorkflowServiceProxy,
    private _userServiceProxy: UserServiceProxy,) { super(injector); }

  ngOnInit() {
    console.log(this.workflowid);
    this.initForm();
  }

  initForm() {
    console.log(this.workflowid);
    this._workflowService.getExecutionPointer(this.workflowid).subscribe(dto => {
          this.primengTableHelper.totalRecordsCount = dto.length;
          this.primengTableHelper.records = dto;
          this.primengTableHelper.hideLoadingIndicator();
          _.forEach(dto, viewItem => {
            console.log(viewItem);
            console.log(viewItem.extensionAttributes.ActionUser);
            this._userServiceProxy.getUserForAll(viewItem.extensionAttributes.ActionUser)
              .subscribe(userResult => {
                console.log(userResult.user.name);
                if (userResult.allOrganizationUnits.length > 0) {
                  viewItem.auditUserName = userResult.user.name;
                } else { viewItem.auditUserName = '-'; }
              });
          });
        });

  }
  getAuditName(item: ExecutionPointerDto) {
    return item.extensionAttributes.Prompt;
  }
}
